<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/layui.css" />
    <link rel="stylesheet" href="/static/css/common.css" />

</head>
<body>
<form class="layui-form" action="" lay-filter="editform">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">表名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="rt_" lay-verify="required|len" autocomplete="off" min="2" placeholder="请输入表名" class="layui-input">
                </div>
            </div>
           
            <div class="layui-form-item">
                <label class="layui-form-label">表注释</label>
                <div class="layui-input-block">
                    <input type="text" name="comment" lay-verify="required|len" autocomplete="off" min="2" placeholder="请输入表注释" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">附加字段</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="fields_id" title="id" checked disabled>
                    <input type="checkbox" name="add_time" title="add_time">
                    <input type="checkbox" name="update_time" title="update_time">
                    <input type="checkbox" name="user_id" title="user_id">
                    <input type="checkbox" name="admin_id" title="admin_id">
                    <input type="checkbox" name="title" title="title">
                    <input type="checkbox" name="names" title="name">
                    <input type="checkbox" name="pid" title="pid">
                    <input type="checkbox" name="content" title="content">
                </div>
            </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-lg layui-btn-warm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>
</form>

<script src="/static/js/layui.js"></script>
<script>
    layui.extend({
            api: '{/}/static/js/api' // 开头特定符 {/} 即代表采用单独路径
        }).use(['api'], function () {
        let form = layui.form
            , layer = layui.layer
            , api = layui.api
			, $ = layui.$;
        form.verify({
            len : (val, item) => {
                let min = item.getAttribute("min")
                if(val.length < min) {
                    return '长度不能小于' + min;
                }
            }
        })
       
        
        //监听提交
        form.on('submit(user-save)', function (data) {
			data = data.field;
            console.log(data)
			api.post('db/createTable', data, res => {
				//console.log(res)
				parent.layui.table.reload("db-table");
				parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
				
			})
           
            return false;
        });



    });
</script>

</body>
</html>